//
//  MTRate.m
//  ebook
//
//  Created by 吴超飞 on 16/5/8.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "MTRate.h"
#import "RateView.h"
#import "EbookNetRequest.h"
#import "ToastView.h"
#import "MTActionSheet.h"

@interface MTRate()<RateViewDelegate>{
    float theRate;
    MTActionSheet *sheet;
}

@end

@implementation MTRate

+(instancetype)shareInstance{
    
    static MTRate *rate = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        rate = [[MTRate alloc] init];
    });
    
    return rate;
}

-(void)rate{
    
    RateView *rateView = [[RateView alloc] init];
    rateView.delegate = self;
    sheet = [[MTActionSheet alloc] initWithView:rateView];
    [sheet show];
}

#pragma mark - RateViewDelegate
-(void)rateView:(RateView *)view rateType:(RateType)type{
    
    NSArray *labelArray = @[@"五星好评", @"我要吐槽", @"稍后再说"];
    
    if (type==AppstoreRate) {//去appstore评分
        NSString *str = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@&pageNumber=0&sortOrdering=2&mt=8", kAppidInAppstore];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kHasRate];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else if(type == Shits){
        
        if ([self.delegate respondsToSelector:@selector(mtRateFeedBack:)]) {
            [self.delegate mtRateFeedBack:self];
        }
    }else if(type == WaitAMoment){//稍候再说
    }
    
    [sheet hide];
}

-(void)rateViewClose:(RateView *)view{
    [sheet hide];
}

@end
